package org.mock.controller;

import com.alibaba.fastjson2.JSONObject;
import lombok.AllArgsConstructor;
import org.mock.service.SabreService;
import org.springframework.web.bind.annotation.*;

/**
 * sabre mock
 *
 * @author AI
 * @since 2020-06-19
 */
@RestController
@AllArgsConstructor
@RequestMapping("sabre/mock")
public class SabreMockController {

    private SabreService sabreService;

    /**
     * getHotelDetails
     *
     * @param request
     * @return
     */
    @PostMapping("/v3.0.0/get/hoteldetails")
    public String getHotelDetails(@RequestBody JSONObject request) {
        return sabreService.getHotelDetails(request);
    }

    /**
     * getHotelAvail
     *
     * @param request
     * @return
     */
    @PostMapping("/v4.0.0/get/hotelavail")
    public String getHotelAvail(@RequestBody JSONObject request) {
        return sabreService.getHotelAvail(request);
    }

    @PostMapping("/v4.0.0/hotel/pricecheck")
    public String priceCheck(@RequestBody JSONObject request) {
        return sabreService.priceCheck(request);
    }

    @PostMapping("/v2.4.0/passenger/records")
    public String createPnr(@RequestBody JSONObject request, @RequestParam String mode) {
        if (mode.equals("create")) {
            return sabreService.createPnr(request);
        } else {
            return "error";
        }
    }

    @PostMapping("/v1/trip/orders/getBooking")
    public String getBooking(@RequestBody JSONObject request) {
        return sabreService.getBooking(request);
    }

    @PostMapping("/v1/trip/orders/cancelBooking")
    public String cancelBooking(@RequestBody JSONObject request) {
        return sabreService.cancelBooking(request);
    }
}
